import React from 'react'
import { BrowserRouter, Redirect, Route, Switch } from 'react-router-dom'
import Login from '../views/Login/index'
import NewDetail from '../views/NewsBrowsing/NewDetail'
import NewsList from '../views/NewsBrowsing/NewsList'
import SandBox from '../views/SandBox/index'

export default function IndexRouter() {
  return (
    <BrowserRouter >
      <Switch>
        <Route path="/news" component={NewsList} />
        <Route path="/detail/:id" component={NewDetail} />
        <Route path="/login" component={Login} />
        <Route path="/" render={() => { return localStorage.getItem("token") ? <SandBox /> : <Redirect to="/login" /> }} />
      </Switch>
    </BrowserRouter>
  )
}
